import { constantRoutes, asyncRoutes } from '@/router'

const state = {
  routers: []
}

const mutations = {
  setRouters(state, data) {
    state.routers = [
      ...constantRoutes,
      ...data
    ]
  }
}

const actions = {
  filterRouter(store, data) {
    const res = asyncRoutes.filter(v => data.includes(v.name))
    store.commit('setRouters', res)
    return res
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
